function esvaziarInput(input){
    var original = input.value;    
    if(input.getAttribute("class") == "password"){
        input.setAttribute("type","password");
    }
    if(!input.ativo){
        input.value = "";
        
        input.onblur = function(){
            if(this.value == ""){
                this.value = original;
                if(this.getAttribute("class") == "password"){
                    this.setAttribute("type","text");
                }
            }else{
                input.ativo = true;
                
            }
        };
    }
}

function confirmar(mensagem, msgOK, msgCancel, f){
    var btns = {};
    btns[msgOK] = function(){
        $( this ).dialog( "close" );
        f(true);
    };
    btns[msgCancel] = function(){ 
        $( this ).dialog( "close" );
        f(false);
    };
    var message = jQuery('<div></div>').html(mensagem);
    message.dialog({
        resizable: false,
        modal: true,
        draggable: false,
        buttons: btns
    });
}

var delay = (function(){
    var timer = 0;
    return function(callback, ms){
        clearTimeout (timer);
        timer = setTimeout(callback, ms);
    };
})();

//helper function to create the form
function getNewSubmitForm(){
    var submitForm = document.createElement("FORM");
    document.body.appendChild(submitForm);
    submitForm.method = "POST";
    return submitForm;
}

//helper function to add elements to the form
function createNewFormElement(inputForm, elementName, elementValue){
    var newElement = document.createElement('input');
    newElement.setAttribute("type", "hidden");
    newElement.setAttribute("name", elementName);
    newElement.setAttribute("value", elementValue);
    inputForm.appendChild(newElement);
    return newElement;
}